package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class MovieAddPage extends InternalPage {
	public MovieAddPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "name")
	private WebElement titleField;

  @FindBy(name = "year")
  private WebElement yearField;

  @FindBy(name = "submit")
  private WebElement submitButton;
  
  public MovieAddPage setTitleField(String text) {
	  titleField.sendKeys(text);
    return this;
  }

  public MovieAddPage setYearField(String text) {
	  yearField.sendKeys(text);
    return this;
  }

  public void clickSubmitButton() {
    submitButton.click();
  }
	
	public MovieAddPage ensurePageLoaded() {
	    wait.until(presenceOfElementLocated(By.name("name")));
	    wait.until(presenceOfElementLocated(By.cssSelector("div.content h2")));
	    return this;
	  }
}
